package com.ruoyi.project.WebMoudle.handleType.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.WebMoudle.handleType.domain.HandleType;
import com.ruoyi.project.WebMoudle.handleType.service.IHandleTypeService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 问题处理类型Controller
 * 
 * @author ruoyi
 * @date 2020-09-01
 */
@Controller
@RequestMapping("/handleType/handleType")
public class HandleTypeController extends BaseController
{
    private String prefix = "handleType/handleType";

    @Autowired
    private IHandleTypeService handleTypeService;

    @RequiresPermissions("handleType:handleType:view")
    @GetMapping()
    public String handleType()
    {
        return prefix + "/handleType";
    }

    /**
     * 查询问题处理类型列表
     */
    @RequiresPermissions("handleType:handleType:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(HandleType handleType)
    {
        startPage();
        List<HandleType> list = handleTypeService.selectHandleTypeList(handleType);
        return getDataTable(list);
    }

    /**
     * 导出问题处理类型列表
     */
    @RequiresPermissions("handleType:handleType:export")
    @Log(title = "问题处理类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(HandleType handleType)
    {
        List<HandleType> list = handleTypeService.selectHandleTypeList(handleType);
        ExcelUtil<HandleType> util = new ExcelUtil<HandleType>(HandleType.class);
        return util.exportExcel(list, "handleType");
    }

    /**
     * 新增问题处理类型
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存问题处理类型
     */
    @RequiresPermissions("handleType:handleType:add")
    @Log(title = "问题处理类型", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(HandleType handleType)
    {
        return toAjax(handleTypeService.insertHandleType(handleType));
    }

    /**
     * 修改问题处理类型
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        HandleType handleType = handleTypeService.selectHandleTypeById(id);
        mmap.put("handleType", handleType);
        return prefix + "/edit";
    }

    /**
     * 修改保存问题处理类型
     */
    @RequiresPermissions("handleType:handleType:edit")
    @Log(title = "问题处理类型", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(HandleType handleType)
    {
        return toAjax(handleTypeService.updateHandleType(handleType));
    }

    /**
     * 删除问题处理类型
     */
    @RequiresPermissions("handleType:handleType:remove")
    @Log(title = "问题处理类型", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(handleTypeService.deleteHandleTypeByIds(ids));
    }
}
